package com.xinhe.web.controller;

import com.querydsl.core.QueryResults;
import com.xinhe.web.annotation.WebUsed;
import com.xinhe.web.common.Result;
import com.xinhe.web.entity.SeckillTime;
import com.xinhe.web.response.SeckillTimeCurrentView;
import com.xinhe.web.response.SeckillTimeLatelyView;
import com.xinhe.web.service.SeckillTimeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;

@Api(value = "秒杀时间", tags = {"秒杀时间"})
@RestController
@RequestMapping(value = {"/seckillTime"}, produces = {"application/json;charset=UTF-8"})

public class SeckillTimeController {
    @Autowired
    private SeckillTimeService seckillTimeService;

    @WebUsed
    @ApiOperation(httpMethod = "GET", value = "分页查询秒杀时间")
    @RequestMapping({"/pageSeckillTime"})
    public QueryResults<SeckillTime> pageSeckillTime(int pageNum, int pageSize) {
        return this.seckillTimeService.pageSeckillTime(pageNum,pageSize);
    }

    @WebUsed
    @ApiOperation(httpMethod = "POST", value = "保存秒杀时间")
    @RequestMapping({"/saveSeckillTime"})
    public Result saveSeckillTime(Long id, Date startTime, Date endTime, String remark) {
        return this.seckillTimeService.saveSeckillTime(id,startTime,endTime,remark);
    }

    @WebUsed
    @ApiOperation(httpMethod = "GET", value = "查询当前时间进行的抢购")
    @RequestMapping({"/findCurrentSeckillTime"})
    public Result<SeckillTimeCurrentView> findCurrentSeckillTime() {
        return this.seckillTimeService.findCurrentSeckillTime();
    }

    @WebUsed
    @ApiOperation(httpMethod = "GET", value = "查询最近时间的抢购")
    @RequestMapping({"/findLatelySeckillTime"})
    public Result<SeckillTimeLatelyView> findLatelySeckillTime() {
        return this.seckillTimeService.findLatelySeckillTime();
    }

    @WebUsed
    @ApiOperation(httpMethod = "GET", value = "删除秒杀时间")
    @ApiImplicitParam(name = "seckillTimeId", value = "标识", required = true)
    @RequestMapping({"/deleteSeckillTime"})
    public Result deleteSeckillTime(Long seckillTimeId) {
        return this.seckillTimeService.delete(seckillTimeId);
    }

    @WebUsed
    @ApiOperation(httpMethod = "GET", value = "秒杀时间详情")
    @ApiImplicitParam(name = "seckillTimeId", value = "标识", required = true)
    @RequestMapping({"/detailSeckillTime"})
    public Result<SeckillTime> detailSeckillTime(Long seckillTimeId) {
        return this.seckillTimeService.findById(seckillTimeId);
    }
}
